<?php
session_start();
function conectarse(){
	$db_host="127.0.0.1";
	$db_nombre="iusm";
	$db_user="iusm";
	$db_pass="iusm";
	$link=mysql_connect($db_host, $db_user, $db_pass) or die ("Error conectando a la base de datos.");
	mysql_select_db($db_nombre ,$link) or die("Error seleccionando la base de datos."); 
	return $link;
}

$user = $_POST["user"];
$pass = $_POST["pass"];
$mail = $_POST["mail"];

$link = conectarse();
$query="INSERT INTO usuarios VALUES ('','".$user."','".$pass."','".$mail."');";
$result=mysql_query($query,$link);
$query2="SELECT LAST_INSERT_ID()";
$result2=mysql_query($query2,$link);
$id = mysql_fetch_row($result2);

function location($url="#"){echo "<script> document.location.href=\"$url\"; </script>";}
$_SESSION["id_usuario"] = $user;
$_SESSION["id"] = $id[0];
location("index.php");
?>